//export const roleData = ;
//import { getAuthority } from '../utils/authority';
// import {getUserInfo} from "../utils/request";

// 权限映射表

// const LastRole = (obj) => {
//   return Object.values(obj).reduce((arr, curr) => {
//     if (curr[1]) {
//       return arr.concat(curr[0]);
//     } else {
//       return arr.concat([]);
//     }
//   }, []);
// };
//
// // 只取最后一节点的值入库
// export const getRoleSet = (role) => {
//   const RoleMap = getRoleDataMap(getPermissionMap());
//   const a = new Set(LastRole(RoleMap));
//   const b = new Set([...role]);
//   // 交集
//   const intersectionSet = [...a].filter(x => b.has(x));
//   return intersectionSet;
// };
//
// // 匹配权限MAP，是否具有权限，相应的值设为true，false
// export const getUserRole = (user_role,role_key) => {
//   if(user_role){
//     user_role.some(item=>{
//        item==role_key
//     })
//   }else{
//     return false;
//   }
// };

// export const getUserRole = (role) => {
//   const RoleMap = getRoleDataMap(getPermissionMap());
//   const RoleMapClone = deepClone(RoleMap);
//   Object.keys(RoleMapClone).forEach((key, i) => {
//     role && role.find((value, index, arr) => {
//       return value == RoleMap[key][0];
//     }) ? RoleMapClone[key] = true : RoleMapClone[key] = false;
//   });
//   return RoleMapClone;
// };

// 对象深拷贝
// const deepClone = (obj) => {
//   const proto = Object.getPrototypeOf(obj);
//   return Object.assign({}, Object.create(proto), obj);
// };

const getPermissionChildren = (permissionLast, data) => {
  return data.map(item => {
    if (item.children) {
      return getPermissionChildren(permissionLast, item.children);
    }
    return permissionLast.push(item.key);
  });
};

const getPermissionLast = (data) => {
  const permissionLast = [];
  data.map(item => {
    if (item.children) {
      getPermissionChildren(permissionLast, item.children);
    } else {
      permissionLast.push(item.key);
    }
  });
  return permissionLast;
};

// 只取最后一节点的值入库
export const getLastPermission = (permissionMap, choosePermission) => {

  const arr_last_child = getPermissionLast(permissionMap);


  const a = new Set(arr_last_child);
  const b = new Set(choosePermission);

  // console.log('arr_last_child',arr_last_child);
  // console.log('choosePermission',choosePermission);
  // 交集
  const intersectionSet = [...a].filter(x => b.has(x));
  // console.log('intersectionSet',intersectionSet);
  return intersectionSet;
};



